home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5984 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Can anyone optimize this VERY simple piece of code?
  5. Date: Thu, 22 Feb 96 01:41:16 GMT
  6. Organization: none
  7. Message-ID: <824953276snz@genesis.demon.co.uk>
  8. References: <19950700wnr@samtech.demon.co.uk> <31276E30.26C0@ix.netcom.com> <824842585snz@genesis.demon.co.uk> <312A863F.49FC@ix.netcom.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <312A863F.49FC@ix.netcom.com>
  15.            hcross@ix.netcom.com "Henry Cross" writes:
  16.  
  17. >Lawrence Kirby wrote:
  18. >> 
  19. >> In article <31276E30.26C0@ix.netcom.com>
  20. >>            hcross@ix.netcom.com "Henry Cross" writes:
  21. >> 
  22. >> >>  Personally I'd use a VERY simple language. Assembly!
  23. >> > This is a job for inline assembly, compiler allowing, or an assembler
  24. >> >if not.
  25. >> > However if you must persist in C, use pointers every place possible.
  26. >> 
  27. >> This hasn't been the case in any reasonable compiler for a number of years
  28. >> now.
  29. >> 
  30. >> > For example vgamem[count] could be a pointer that incremented++ vice
  31. >> > an index to an array. (Which is very expensive computationally.)
  32. >> 
  33. >> The strength reduction required to convert an index to a pointer is one
  34. >> of the simpler optimistaion that compilers perform. Code that uses indices
  35. >> often provides more information to the compiler for optimisation purposes so
  36. >> may even result in better code generated.
  37. >
  38. > Your mileage may vary, according to compiler. The only certain solution
  39. >would be to examine the code generated by the compiler with the
  40. >appropriate options turned on.
  41.  
  42. While it may be useful in this case it is a bad idea in general to
  43. cramp/obfuscate your coding style simply to support prehistoric compilers.
  44. Clarity is more important in the vast majority of cases.
  45.  
  46. In this case it is not likely to make much difference. A more radical change
  47. is needed for a larger improvement in speed e.g. converting the inner
  48. loop to a memcpy call, or at least taking as much calculation out of
  49. it as possible (but again a good compiler may do this for you) and try
  50. to copy words rather than single chars at a time.
  51.  
  52. The real problems here are dealing with VGA memory and far pointers, and
  53. being as efficient as possible on the PC archetecture specifically.
  54. So this thread is best moved to comp.os.msdos.programmer.
  55.  
  56. -- 
  57. -----------------------------------------
  58. Lawrence Kirby | fred@genesis.demon.co.uk
  59. Wilts, England | 70734.126@compuserve.com
  60. -----------------------------------------
  61.